/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author usuario
 */
@Entity
@Table(name = "itemventa")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Itemventa.findAll", query = "SELECT i FROM Itemventa i"),
    @NamedQuery(name = "Itemventa.findByNroitem", query = "SELECT i FROM Itemventa i WHERE i.itemventaPK.nroitem = :nroitem"),
    @NamedQuery(name = "Itemventa.findByIdventa", query = "SELECT i FROM Itemventa i WHERE i.itemventaPK.idventa = :idventa"),
    @NamedQuery(name = "Itemventa.findByCantidad", query = "SELECT i FROM Itemventa i WHERE i.cantidad = :cantidad"),
    @NamedQuery(name = "Itemventa.findByIva", query = "SELECT i FROM Itemventa i WHERE i.iva = :iva"),
    @NamedQuery(name = "Itemventa.findByVlrtotal", query = "SELECT i FROM Itemventa i WHERE i.vlrtotal = :vlrtotal")})
public class Itemventa implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ItemventaPK itemventaPK;
    @Basic(optional = false)
    @Column(name = "cantidad")
    private int cantidad;
    @Basic(optional = false)
    @Column(name = "iva")
    private double iva;
    @Basic(optional = false)
    @Column(name = "vlrtotal")
    private double vlrtotal;
    @JoinColumn(name = "idventa", referencedColumnName = "idventa", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Venta venta;
    @JoinColumn(name = "idproducto", referencedColumnName = "idproducto")
    @ManyToOne(optional = false)
    private Producto idproducto;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "itemventa")
    private Collection<Devolucion> devolucionCollection;

    public Itemventa() {
    }

    public Itemventa(ItemventaPK itemventaPK) {
        this.itemventaPK = itemventaPK;
    }

    public Itemventa(ItemventaPK itemventaPK, int cantidad, double iva, double vlrtotal) {
        this.itemventaPK = itemventaPK;
        this.cantidad = cantidad;
        this.iva = iva;
        this.vlrtotal = vlrtotal;
    }

    public Itemventa(String nroitem, String idventa) {
        this.itemventaPK = new ItemventaPK(nroitem, idventa);
    }

    public ItemventaPK getItemventaPK() {
        return itemventaPK;
    }

    public void setItemventaPK(ItemventaPK itemventaPK) {
        this.itemventaPK = itemventaPK;
    }

    public int getCantidad() {
        return cantidad;
    }

    public void setCantidad(int cantidad) {
        this.cantidad = cantidad;
    }

    public double getIva() {
        return iva;
    }

    public void setIva(double iva) {
        this.iva = iva;
    }

    public double getVlrtotal() {
        return vlrtotal;
    }

    public void setVlrtotal(double vlrtotal) {
        this.vlrtotal = vlrtotal;
    }

    public Venta getVenta() {
        return venta;
    }

    public void setVenta(Venta venta) {
        this.venta = venta;
    }

    public Producto getIdproducto() {
        return idproducto;
    }

    public void setIdproducto(Producto idproducto) {
        this.idproducto = idproducto;
    }

    @XmlTransient
    public Collection<Devolucion> getDevolucionCollection() {
        return devolucionCollection;
    }

    public void setDevolucionCollection(Collection<Devolucion> devolucionCollection) {
        this.devolucionCollection = devolucionCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (itemventaPK != null ? itemventaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Itemventa)) {
            return false;
        }
        Itemventa other = (Itemventa) object;
        if ((this.itemventaPK == null && other.itemventaPK != null) || (this.itemventaPK != null && !this.itemventaPK.equals(other.itemventaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Itemventa[ itemventaPK=" + itemventaPK + " ]";
    }
    
}
